package com.lagou.edu.minicat.core;

import com.lagou.edu.minicat.base.LifecycleBase;
import lombok.Data;

@Data
public class Host extends LifecycleBase {

    private Engine engine;

    private String name;

    private String appBase;

    private Context[] contexts = new Context[0];

    public void addContext(Context context) {
        Context[] newContexts = new Context[contexts.length + 1];
        System.arraycopy(this.contexts, 0, newContexts, 0, this.contexts.length);
        newContexts[contexts.length] = context;
        this.contexts = newContexts;
    }

    @Override
    protected void initInternal() {
        for (Context context : contexts) {
            context.init();
        }
    }

    @Override
    protected void startInternal() {
        for (Context context : contexts) {
            context.start();
        }
    }
}
